package com.czw.ddm.app;

import android.content.Context;
import android.util.Log;

import androidx.annotation.Keep;
import androidx.multidex.MultiDex;

import com.czw.ddm.BuildConfig;
import com.taobao.sophix.SophixApplication;
import com.taobao.sophix.SophixEntry;
import com.taobao.sophix.SophixManager;

public class SophixStubApplication extends SophixApplication {
    private final String TAG = "SophixStubApplication";

    @Keep
    @SophixEntry(MainApplication.class)//只有这里改成自己的Application类，下面static不要改
    static class RealApplicationStub {
    }

    //这里不能调用非系统API的类
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //如用到MultiDex，必须在此初始化
        MultiDex.install(this);
        initSophix();
    }

    private void initSophix() {
        String appVersion = "0.0.0";
        try {
            appVersion = getBaseContext().getPackageManager()
                    .getPackageInfo(this.getPackageName(), 0).versionName;
        } catch (Exception e) {
            appVersion = "1.0.0";
        }
        final SophixManager instance = SophixManager.getInstance();
        instance.setContext(this)
                .setAppVersion(appVersion)
               // .setAesKey(null)
                .setEnableDebug(BuildConfig.DEBUG)
                .setSecretMetaData(com.mtzqc.common.BuildConfig.HOTFIX_ID_SECRET,
                        com.mtzqc.common.BuildConfig.EMAS_APP_SECRET,
                        com.mtzqc.common.BuildConfig.HOTFIX_RSA_SECRET
                )
                .setEnableFullLog()
                .setPatchLoadStatusStub((mode, code, info, handlePatchVersion) -> {
                    String msg = new StringBuilder().append("Mode:").append(mode)
                            .append(" Code:").append(code)
                            .append(" Info:").append(info)
                            .append(" HandlePatchVersion:").append(handlePatchVersion).toString();
                    Log.d(TAG, "sophix  onLoad " + msg);
                }).initialize();
    }

}